﻿using System;
#if DEBUG
using System.Diagnostics;
#endif // #if DEBUG
using System.Net;
using System.Xml;
using System.Collections.Generic;

using FRL.DebtChased.Extensions;

#if WORKFLOWEDITOR
using FRL.DebtChased.WorkflowEditor;
#endif //

#if REPOSITORY
using FRL.DebtChased.Repository;
#endif // #if REPOSITORY

namespace FRL.DebtChased.WorkflowObjects
{

	/// <summary>
	/// Declaration of WorkflowAction_Popup class
	/// Workflow action for popping up a form
	/// </summary>
	public class WorkflowAction_Popup : WorkflowAction_Base
	{

		/////////////////////////////////////////////////////////////
		// Constants

		public const string XmlElementName = "WorkflowAction_Popup";
		public const string BoingLabel = "Form";

		/////////////////////////////////////////////////////////////
		// Attributes

		private int m_iPopupId;
		public int PopupId
		{
			get { return m_iPopupId; }
			set { m_iPopupId = value; }
		}

		/////////////////////////////////////////////////////////////
		// Implementation

		protected override string _getElementName()
		{
			return XmlElementName;
		}

#if WORKFLOWEDITOR
		public override string GetBoingLabel()
		{
			return BoingLabel;
		}
#endif // #if WORKFLOWEDITOR

#if WORKFLOWEDITOR
		public override string[] GetBoingSubStrings()
		{

			// Declare return variable
			string[] Ftmp = new string[2];

			// Show popup in top rop
			string strPopupName = CachedData.Singleton.GetPopupName(m_iPopupId);
			if(strPopupName!=null)
				Ftmp[0] = string.Format("Popup \"{0}\"", strPopupName);
			else
				Ftmp[0] = "Popup [none]";

			// Show parameters in second row
			Ftmp[1] = "[no parameters]";

			// Return variable
			return Ftmp;

		}
#endif // #if WORKFLOWEDITOR

		protected override void _writeParameters(XmlWriter w)
		{

			// Write members as parameters
			w.WriteAttributeString("popupId", m_iPopupId.ToString());

		}

		protected override void _readParameters(XmlReader r)
		{

			// Read parameters
			m_iPopupId = r.SafeReadIntAttribute("popupId", 0);

		}

		public override void GetObjectsUsed(List<int> iCommBodiesUsed, List<int> iPopupsUsed, List<int> iLetterTypeIds)
		{

			// Add the popup ids
			iPopupsUsed.AddUniqueNonZeroValue(m_iPopupId);

		}

		public override string GetSummary(Workflow.eSummaryFormat SummaryFormat)
		{

			// Declare return variable
			string strFtmp = null;

			// Compare formats
			if (SummaryFormat == Workflow.eSummaryFormat.Audit)
			{
				strFtmp = "Form";
			}
			else if (SummaryFormat == Workflow.eSummaryFormat.Clockwork)
			{
				strFtmp = "Form";
			}
#if DEBUG
			else
				Debug.Assert(false);
#endif // #if DEBUG

			// Return variable
			return strFtmp;

		}

#if REPOSITORY
		public override List<AccountNote> Process(DebtChasedEntities ent, Account acc, AccountInvoice inv)
		{

			// Declare return variable
			List<AccountNote> Ftmp = null;

			// Return variable
			return Ftmp;

		}
#endif // #if REPOSITORY

	}

}
